﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using Model;

namespace BusinessLogic
{
    public class GetUserCommand : BaseCommand<acm_user>
    {
        public GetUserCommand(string uname, string passwd)
        {               //   0     1          2            3          4         5
            SetQuery("select id,user_role,dealer_code,dealer_name,user_name,user_password from acm_user where user_name='" + uname + "' and user_password='" + passwd + "'");
        }

        public GetUserCommand(int userId)
        {               //   0     1          2            3          4         5
            SetQuery("select id,user_role,dealer_code,dealer_name,user_name,user_password from acm_user where id=" + userId.ToString());
        }

        public override void Command()
        {
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();

            if (dr.HasRows)
            {
                Result = new acm_user();
                Result.id = GetNullableInt(dr,0);
                Result.user_role = GetNullableString(dr,1);
                Result.dealer_code = GetNullableString(dr, 2);
                Result.dealer_name = GetNullableString(dr, 3);
                Result.user_name = GetNullableString(dr, 4);
                Result.user_password = GetNullableString(dr, 5);
            }
        }
    }
}
